<?php

final class SQLTransaction {

    private static $conn;

    private function __construct() {
        
    }

    public static function open() {
        if (!isset(self::$conn)) {
            self::$conn = SQLConnection::open();
            self::$conn->beginTransaction();
        }
    }

    /**
     *
     * @return PDO
     */
    public static function get() {
        if (!isset(self::$conn))
            throw new NonActiveSQLConnectionException();
        return self::$conn;
    }

    public static function rollback() {
        if (isset(self::$conn)) {
            self::$conn->rollBack();
            self::$conn = NULL;
        }
    }

    public static function commit() {
        if (isset(self::$conn)) {
            self::$conn->commit();
            self::$conn = NULL;
        }
    }

}
